﻿<!DOCTYPE HTML>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<!-- 插入公共模板 _meta -->
<head th:insert="../templates/admin/common/_meta :: common_meta"></head>
<body>

<!-- 插入公共模板 _header -->
<div th:replace="../templates/admin/common/_header :: common_header"></div>

<!-- 插入公共模板 _menu -->
<div th:replace="../templates/admin/common/_menu :: common_menu"></div>

<section class="Hui-article-box">
	<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 商品管理 <span class="c-gray en">&gt;</span> 商品列表<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
	<div class="Hui-article">
		<article class="cl pd-20">
			<div class="cl pd-5 bg-1 bk-gray mt-20">
				<span class="l">
					<a href="javascript:;" onclick="order_delBatch()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
				</span>
				<span class="r">共有数据：<strong th:text="${orderVOList.size()}"></strong> 条</span>
			</div>
			<div class="mt-20">
				<table class="table table-border table-bordered table-hover table-bg table-sort">
					<thead>
						<tr class="text-c">
							<th width="15"><input type="checkbox" ></th>
							<th width="30">序号</th>
							<th width="80">订单号</th>
							<th width="120">所购商品</th>
							<th width="120">收货地址</th>
							<th width="80">订单总金额</th>
							<th width="50">支付状态</th>
							<th width="50">物流状态</th>
							<th width="100">下单时间</th>
							<th width="100">发货时间</th>
							<th width="60">购买账户</th>
							<th width="60">操作</th>
						</tr>
					</thead>
					<tbody>
						<tr class="text-c" th:each="orderVO,var : ${orderVOList}">
							<td><input type="checkbox" th:value="${orderVO.orderId}" name="orderId"></td>
							<td th:text="${var.count}"></td>
							<td th:text="${orderVO.orderNumber}"></td>
							<td>
								<div style="float:left">
									<th:block th:each="orderChildVO : ${orderVO.orderChildVOList}">
										<img style="width:40px" th:src="|@{'' + ${orderChildVO.goods.image} + ''}|" th:alt="${orderChildVO.goods.goodsName}"/>
										<span th:text="|${orderChildVO.goods.goodsName} x ${orderChildVO.quantity}件|"></span>
										<br/>
									</th:block>
								</div>
							</td>
							<td th:text="|${orderVO.userReceive.receiveProvince} ${orderVO.userReceive.receiveCity} ${orderVO.userReceive.receiveCounty} ${orderVO.userReceive.receiveAddress}    (${orderVO.userReceive.contact} 收) ${orderVO.userReceive.tel}|"></td>
							<td th:text="|${#numbers.formatDecimal(orderVO.totalAmount/100.0,1,2)}元|"></td>
							<td class="td-status">
								<span class="label label-defaunt radius" th:if="${orderVO.payState == 1}">未付款</span>
								<span class="label label-success radius" th:if="${orderVO.payState == 2}">已付款</span>
							</td>
							<td class="td-status1">
								<span class="label label-warning radius" th:if="${orderVO.logisticsState == 1}">待配送</span>
								<span class="label label-secondary radius" th:if="${orderVO.logisticsState == 2}">已配送</span>
								<span class="label label-success radius" th:if="${orderVO.logisticsState == 3}">已确认收货</span>
							</td>
							<td th:with="createTime=${orderVO.createTime}" th:text="${#dates.format(createTime, 'yyyy-MM-dd HH:mm:ss')}"></td>
							<td th:with="sendTime=${orderVO.sendTime}" th:text="${#dates.format(sendTime, 'yyyy-MM-dd HH:mm:ss')}"></td>
							<td th:text="${orderVO.user.userName}"></td>
							<td class="td-manage">
								<a title="确认发货" th:if="${orderVO.logisticsState == 1 and orderVO.payState == 2}" style="text-decoration:none" th:onclick="|order_send(this,${orderVO.orderId})|" href="javascript:;"><i class="Hui-iconfont">&#xe669;</i></a>
								<a title="编辑" style="text-decoration:none" class="ml-5"  th:onclick="|order_edit('编辑','goOrderEdit',${orderVO.orderId},'','650')|" href="javascript:;" ><i class="Hui-iconfont">&#xe6df;</i></a>
								<a title="删除" href="javascript:;" th:onclick="|order_del(this,${orderVO.orderId})|" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</article>
	</div>
</section>

<!-- 插入公共模版 _footer -->
<div th:replace="../templates/admin/common/_footer :: common_footer"></div>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../../lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="../../lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" th:inline="none">
	/*订单-编辑*/
	function order_edit(title,url,orderId,w,h){
		url = url + "?orderId=" + orderId;
		layer_show(title,url,w,h);
	}

	/*订单-删除*/
	function order_del(obj,orderId){
		layer.confirm('确认要删除吗？',function(index){
			$.ajax({
				type: "GET",
				dateType: "json",
				url: "/orderAction/doOrderDelete",
				data:{orderId:orderId},
				success: function (result) {
					if(result.flag == "true") {
						$(obj).parents("tr").remove();
						layer.msg('已删除!',{icon:1,time:1000});
					} else {
						layer.msg('删除失败!',{icon: 2,time:1000});
					}
				},
				error: function (err) {
					layer.msg('请求异常!',{icon: 2,time:1000})
				}
			});
		});
	}


	/*订单-批量删除*/
	function order_delBatch() {
		var obj = document.getElementsByName("orderId");
		var orderIds = [];
		for(i in obj) {
			if(obj[i].checked){
				orderIds.push(obj[i].value);
			}
		}
		console.log(orderIds);
		layer.confirm('确认要删除吗？',function(index){
			$.ajax({
				type: "GET",
				dateType: "json",
				url: "doDelBatchOrder",
				data: {orderIds:orderIds},
				success: function (result) {
					if(result.flag = "true") {
						layer.msg('删除成功,请刷新!',{icon: 6,time:1000});
					} else {
						layer.msg('失败,含有'+result.number+'个删除失败!',{icon: 2,time:1000});
					}
				},
				error: function (err) {
					layer.msg('请求异常!',{icon: 2,time:1000})
				}
			});
		});
	}

	/*订单-确认发货*/
	function order_send(obj,orderId){
		layer.confirm('确认已经发货吗？',function(index){
			$.ajax({
				type: "GET",
				dateType: "json",
				url: "doOrderLogisticsUpdate",
				data: {orderId:orderId, logisticsState:2},
				success: function (result) {
					if(result.flag = "true") {
						$(obj).parents("tr").find(".td-status1").html('<span class="label label-secondary radius">已配送</span>');
						$(obj).remove();
						layer.msg('已确认,请刷新!',{icon: 6,time:1000});
					} else {
						layer.msg('确认失败!',{icon: 2,time:1000});
					}
				},
				error: function (err) {
					layer.msg('请求异常!',{icon: 2,time:1000})
				}
			});
		});
	}



	/* 表格配置 */
	$(function(){
		$('.table-sort').dataTable({
			"aaSorting": [[ 1, "asc" ]],//默认第几个排序
			"bStateSave": true,//状态保存
			"aoColumnDefs": [
			  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
			  {"orderable":false,"aTargets":[0,11]}// 制定列不参与排序
			]
		});


	});

</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>